package com.huawei.hwid.core.d;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build.VERSION;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hwid.core.d.b.e;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;

public class o {
    public static final boolean a = (VERSION.SDK_INT >= 11);

    public static void a(Context context, String str, int i) {
        if (b.g()) {
            Toast.makeText(context, str, i).show();
            return;
        }
        int b = b(context);
        if (b != 0) {
            context.setTheme(b);
        }
        Toast.makeText(context, str, i).show();
    }

    public static int a(Context context) {
        if (context == null) {
            e.b("UIUtil", "getDialogThemeId, context is null", true);
            return 3;
        }
        int b = b(context);
        if (VERSION.SDK_INT < 16 || b == 0) {
            return 3;
        }
        return 0;
    }

    public static int b(Context context) {
        if (d.a()) {
            return context.getResources().getIdentifier("androidhwext:style/Theme.Emui.Dark", null, null);
        }
        return context.getResources().getIdentifier("androidhwext:style/Theme.Emui", null, null);
    }

    public static void c(Context context) {
        if (context != null) {
            try {
                Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
                intent.setData(Uri.fromParts(HiAnalyticsConstant.BI_KEY_PACKAGE, context.getPackageName(), null));
                context.startActivity(intent);
            } catch (RuntimeException e) {
                e.d("UIUtil", "RuntimeException", true);
            } catch (Exception e2) {
                e.d("UIUtil", "Exception", true);
            }
        }
    }

    public static void a(Context context, int i) {
        a(context, context.getString(i), 1);
    }

    public static Builder a(Context context, String str, String str2) {
        e.b("UIUtil", "createRefusePermissionBuild", true);
        Builder builder = new Builder(context, a(context));
        View inflate = View.inflate(context, l.c(context, "cloudsetting_refuse_permission_dialog"), null);
        ((TextView) inflate.findViewById(l.d(context, "text1"))).setText(str);
        ((TextView) inflate.findViewById(l.d(context, "text2"))).setText(str2);
        builder.setView(inflate).setPositiveButton(l.a(context, "CS_go_settings"), new 1(context)).setNegativeButton(17039360, null);
        return builder;
    }

    public static void a(Activity activity) {
        try {
            activity.getWindow().getAttributes().getClass().getDeclaredField("layoutInDisplayCutoutMode").set(activity.getWindow().getAttributes(), Integer.valueOf(1));
        } catch (RuntimeException e) {
            e.d("UIUtil", "RuntimeException: " + e.getClass().getSimpleName(), true);
        } catch (Exception e2) {
            e.d("UIUtil", "Exception: " + e2.getClass().getSimpleName(), true);
        }
    }

    public static void a(Dialog dialog) {
        if (e.a()) {
            try {
                dialog.getWindow().getAttributes().getClass().getDeclaredField("layoutInDisplayCutoutMode").set(dialog.getWindow().getAttributes(), Integer.valueOf(1));
            } catch (RuntimeException e) {
                e.d("UIUtil", "RuntimeException: " + e.getClass().getSimpleName(), true);
            } catch (Exception e2) {
                e.d("UIUtil", "Exception: " + e2.getClass().getSimpleName(), true);
            }
        }
    }

    public static void b(Activity activity) {
        if (e.b() && activity != null) {
            e.b("UIUtil", "setEMUI10StatusBarColor start.", true);
            Window window = activity.getWindow();
            int systemUiVisibility = activity.getWindow().getDecorView().getSystemUiVisibility() | 8192;
            window.clearFlags(201326592);
            window.getDecorView().setSystemUiVisibility((systemUiVisibility | WXMediaMessage.DESCRIPTION_LENGTH_LIMIT) | 256);
            window.addFlags(Integer.MIN_VALUE);
            window.setStatusBarColor(0);
            c(activity);
        }
    }

    public static void c(Activity activity) {
        if (activity != null) {
            View childAt = ((ViewGroup) activity.getWindow().findViewById(16908290)).getChildAt(0);
            if (childAt != null) {
                childAt.setFitsSystemWindows(true);
            }
        }
    }
}
